package com.zhou.project.modules.activity.activity.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.project.modules.activity.activity.entity.Activity;
import com.zhou.project.modules.activity.activity.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("activity/act")
@Api(tags = "[活动创建]")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @PostMapping
    @ApiOperation("活动的创建")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "活动得名称", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "introduce",value = "活动的介绍",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "universityId",value = "大学的标号",required = true,dataTypeClass = Integer.class)
    })
    @PreAuthorize("hasAuthority('posts:save')")
    public void save(@RequestBody @ApiIgnore @Valid Activity entity) {
        activityService.save(entity);
    }

    @GetMapping
    @ApiOperation("活动的分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "活动得名称", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "introduce",value = "活动的介绍",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "universityId",value = "大学的标号",required = true,dataTypeClass = Integer.class)
    })
    public Page<Activity> page(@RequestBody @Valid Activity entity){
        return activityService.page(entity);
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasAuthority('activity:delete')")
    public void delete(@PathVariable @NotNull(message = "想要删除的活动id不能为空") int id){
        activityService.removeById(id);
    }



}
